package com.banmao.algorithm.No1To100.No4_Median_of_Two_Sorted_Arrays;

class Solution01 {
    static double findMedianSortedArrays(int[] nums1, int[] nums2) {
        int len = nums1.length+nums2.length;
        int[] list = new int[len];
        int m = 0, i=0, j=0;
        while(i<nums1.length && j<nums2.length) {
            if(nums1[i]<nums2[j]){
                list[m++] = nums1[i++];
            } else {
                list[m++] = nums2[j++];
            }
        }
        if(i != nums1.length){
            for( ; i<nums1.length; i++){
                list[m++] = nums1[i];
            }
        } else {
            for( ; j<nums2.length;j++){
                list[m++] = nums2[j];
            }
        }

        double count;
        if(len%2!=0){
            count = list[len/2];
            return count;
        } else {
            count =  ((double)list[len/2]+(double)list[len/2-1])/2;
            return count;
        }
    }
}
